package com.xiaotao.learn.enuml;
enum  ErrorInfo {
    PASSWORD_ERROR(114514, "密码错误"),
    USER_NOT_EXIST(1919810, "用户不存在"),
    PASSWORD_ERROR1(114514, "密码错误"),
    USER_NOT_EXIST2(1919810, "用户不存在"),
    PASSWORD_ERROR3(114514, "密码错误"),
    USER_NOT_EXIST4(1919810, "用户不存在"),
    PASSWORD_ERROR5(114514, "密码错误"),
    USER_NOT_EXIST6(1919810, "用户不存在");

    private final int num;
    private final String msg;

    ErrorInfo(int num, String msg) {
        this.num = num;
        this.msg = msg;
    }

    public int getNum() {
        return num;
    }

    public String getMsg() {
        return msg;
    }
}

class MyException extends RuntimeException {
    private final String msg;
    private final int code;
    public MyException(ErrorInfo errorInfo) {
        super(errorInfo.getMsg());
        msg = errorInfo.getMsg();
        code = errorInfo.getNum();
    }

    @Override
    public String toString() {
        return "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
    }
}


public class EnumLearn {
    public static void main(String[] args) {
        throw new MyException(ErrorInfo.USER_NOT_EXIST);
    }
}
